# todo options

# "3:1:1"
split_dir_name = "3_1_1"


Dir.chdir( "T:/Files/uci_binary_datasets" )

Dir.mkdir( split_dir_name ) unless ( File.exist?( split_dir_name ) )
entries = Dir.glob( "*.arff" )

entries.each { | entry |
	folder_name1 = "#{split_dir_name}/#{entry}"
	Dir.mkdir( folder_name1 ) unless ( File.exist?( folder_name1 ) )

	for i in 1..5
		folder_name2 = "#{split_dir_name}/#{entry}/#{i}"
		Dir.mkdir( folder_name2 ) unless ( File.exist?( folder_name2 ) )
	end
}


=begin
java weka.filters.supervised.instance.StratifiedRemoveFolds -i data/soybean.arff -o soybean-train.arff \
   -c last -N 4 -F 1 -V
java weka.filters.supervised.instance.StratifiedRemoveFolds -i data/soybean.arff -o soybean-test.arff \
   -c last -N 4 -F 1

java weka.filters.supervised.instance.Resample -i soybean.arff -o soybean-100%.arff -c last -S 1 -B 1 -Z 100
=end

folds = 5
folds_for_query = folds - 1
java_weka_stratified_class = "java -cp T:/Files/weka/dist/weka.jar weka.filters.supervised.instance.StratifiedRemoveFolds"
java_weka_resample_class = "java -cp T:/Files/weka/dist/weka.jar weka.filters.supervised.instance.Resample"

entries.each { | entry |
	for i in 1..5
		system java_weka_stratified_class + " \
-i #{entry} \
-o #{split_dir_name}/#{entry}/#{i}/temp-stratified.arff \
-c last -N #{folds} -F #{i} -V"

		system java_weka_stratified_class + " \
-i #{entry} \
-o #{split_dir_name}/#{entry}/#{i}/test-stratified.arff \
-c last -N #{folds} -F #{i}"

		system java_weka_stratified_class + " \
-i #{split_dir_name}/#{entry}/#{i}/temp-stratified.arff \
-o #{split_dir_name}/#{entry}/#{i}/query-stratified.arff \
-c last -N #{folds_for_query} -F 1"

		system java_weka_stratified_class + " \
-i #{split_dir_name}/#{entry}/#{i}/temp-stratified.arff \
-o #{split_dir_name}/#{entry}/#{i}/training-stratified.arff \
-c last -N #{folds_for_query} -F 1 -V"




 		system java_weka_resample_class + " \
-i #{split_dir_name}/#{entry}/#{i}/training-stratified.arff \
-o #{split_dir_name}/#{entry}/#{i}/training.arff \
-c last -S 1 -B 1 -Z 100"

 		system java_weka_resample_class + " \
-i #{split_dir_name}/#{entry}/#{i}/query-stratified.arff \
-o #{split_dir_name}/#{entry}/#{i}/query.arff \
-c last -S 1 -B 1 -Z 100"

 		system java_weka_resample_class + " \
-i #{split_dir_name}/#{entry}/#{i}/test-stratified.arff \
-o #{split_dir_name}/#{entry}/#{i}/test.arff \
-c last -S 1 -B 1 -Z 100"
	end
}

